package com.beemans.common.app.ui.fragments

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import com.beemans.common.app.R
import com.beemans.common.app.databinding.FragmentStickyBinding
import com.beemans.common.app.ui.base.BaseFragment
import com.beemans.common.ext.setPageBack
import com.beemans.common.ui.adapter.CustomFragmentStateAdapter
import com.tiamosu.databinding.delegate.lazyDataBinding
import com.tiamosu.databinding.page.DataBindingConfig
import com.tiamosu.fly.ext.clickNoRepeat

/**
 * @author tiamosu
 * @date 2021/8/30.
 */
class StickyFragment : BaseFragment() {
    private val dataBinding: FragmentStickyBinding by lazyDataBinding()

    private var title: String? = null

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_sticky)
    }

    override fun initParameters(bundle: Bundle?) {
        title = getString(MainFragment.PARAM_TITLE)
    }

    override fun initView(rootView: View?) {
        dataBinding.stickyTitleBar.setTvTitle { text = title }
    }

    override fun onFlyLazyInitView() {
        super.onFlyLazyInitView()

        val fragments = mutableListOf<Fragment>().apply {
            add(StickyChildFragment())
            add(StickyChildFragment())
        }
        CustomFragmentStateAdapter(this, dataBinding.stickyVp, fragments)

        postDelayed({
            showToast("可永久吸顶啦~")
            dataBinding.stickySv.isStickyMode = true
        }, 2000)
    }

    override fun initEvent() {
        dataBinding.stickyTitleBar.setPageBack()

        dataBinding.stickySv.setStickyFixedListener { isStickyFixed ->
            Log.e("susu", "isStickyFixed:$isStickyFixed   ${dataBinding.stickySv.isStickyFixed()}")
        }

        dataBinding.stickyTvStickyFixed.clickNoRepeat {
            showToast("永久吸顶解锁啦~")
            dataBinding.stickySv.unStickyFixed(true)
        }
    }

    override fun doBusiness() {
    }
}